﻿@model Manager.Model.Admin.M_User

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Add</h2>
<script type="text/javascript">
    $(function () {
        GetProvince();
        $("#UserAddrProvince").change(function () { GetCity() });
        $("#UserAddrCity").change(function () { GetDistrict() });
    });
    function GetProvince() {
        $("#UserAddrProvince").empty();$.getJSON("/User/GetProvince/", function (data) {
            $.each(data, function (i, item) {
                $("<option></option>").val(item["ProvinceID"])
                .text(item["ProvinceName"])
                .appendTo($("#UserAddrProvince"));
            });
            GetCity();
        }); 
    }
    function GetCity() {
        $("#UserAddrCity").empty();
        var url = "/User/GetCity/" + $("#UserAddrProvince").val() + "/";
        
        $.getJSON(url, function (data) {
            
            $.each(data, function (i, item) {
                $("<option></option>")
                                        .val(item["CityID"])
                                        .text(item["CityName"])
                                        .appendTo($("#UserAddrCity"));
            });
            GetDistrict();
        });
        
    }
    function GetDistrict() {
        $("#UserAddrDistrict").empty();
        var url = "/User/GetDistrict/" + $("#UserAddrCity").val() + "/";
        $.getJSON(url, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>")
                                        .val(item["DistrictID"])
                                        .text(item["DistrictName"])
                                        .appendTo($("#UserAddrDistrict"));
            });
        });
    }   
</script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>M_User</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserNickName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserNickName)
            @Html.ValidationMessageFor(model => model.UserNickName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserPwd)
        </div>
        <div class="editor-field">
            @Html.PasswordFor(model => model.UserPwd)
            @Html.ValidationMessageFor(model => model.UserPwd)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserName)
            @Html.ValidationMessageFor(model => model.UserName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserGender)
        </div>
        <div class="editor-field">
            @Html.RadioButtonFor(model => model.UserGender, true, new { @id = "UserGender1", @checked = "true" })男
            @Html.RadioButtonFor(model => model.UserGender, false, new { @id = "UserGender2" })女
            @Html.ValidationMessageFor(model => model.UserGender)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserEmail)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserEmail)
            @Html.ValidationMessageFor(model => model.UserEmail)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserTel)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserTel)
            @Html.ValidationMessageFor(model => model.UserTel)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserAddrProvince)
        </div>
        <div class="editor-field">
            <select id="UserAddrProvince" name="UserAddrProvince"></select>
            @Html.ValidationMessageFor(model => model.UserAddrProvince)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserAddrCity)
        </div>
        <div class="editor-field">
            <select id="UserAddrCity" name="UserAddrCity"></select>
            @Html.ValidationMessageFor(model => model.UserAddrCity)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserAddrDistrict)
        </div>
        <div class="editor-field">
            <select id="UserAddrDistrict" name="UserAddrDistrict"></select>
            @Html.ValidationMessageFor(model => model.UserAddrDistrict)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

